package io.itit.ecp.admin.provide.renderer;

import io.itit.ecp.admin.server.entity.EmissionReductionFactorEntity;
import io.itit.ecp.admin.server.service.IEmissionReductionFactorService;
import io.itit.grass.estelle.starter.parse.AbstractParseRenderer;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *
 * @Author：Roy
 * @Description：碳减因子导入解析器
 * @Date：Create by 2023-11-23 16:28:52
 */
@Scope("prototype")
@Component(EmissionReductionFactorRenderer.ENTITY_NAME)
public class EmissionReductionFactorRenderer extends AbstractParseRenderer<EmissionReductionFactorEntity> {

    public static final String ENTITY_NAME = "emissionReductionFactorRenderer";

    @Resource
    private IEmissionReductionFactorService emissionReductionFactorService;

    @Override
    public String entityName() {
        return ENTITY_NAME;
    }

    @Override
    public Class<EmissionReductionFactorEntity> getClazz() {
        return EmissionReductionFactorEntity.class;
    }


    @Override
    public int processAfter(List<EmissionReductionFactorEntity> resultList) {
        if (CollectionUtils.isEmpty(resultList)) {
            return 0;
        }
        emissionReductionFactorService.saveBatch(resultList, BATCH_SIZE);
        return resultList.size();
    }
}
